package com.ruoyi.web.controller.security;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.security.dto.backtest.SecurityGridTradingBacktestParamDto;
import com.ruoyi.security.dto.backtest.SecurityGridTradingBacktestResultDto;
import com.ruoyi.security.service.backtest.gridtrading.service.ISecurityGridTradingBacktestService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * @author yeoman
 * @date 2025/11/8 21:41
 * @description 网格交易回测控制器
 */
@Slf4j
@Controller
@RequestMapping("/security/grid-trading-backtest")
public class SecurityGridTradingBacktestController extends BaseController {

    private String prefix = "security";

    @Resource
    private ISecurityGridTradingBacktestService gridTradingBacktestService;

    /**
     * 网格交易回测页面
     */
    @GetMapping()
    public String gridTradingBacktest()
    {
        return prefix + "/grid-trading-backtest";
    }

    /**
     * 网格交易回测
     */
    @PostMapping("/backtest")
    @ResponseBody
    public AjaxResult backtest(@RequestBody @Validated SecurityGridTradingBacktestParamDto param) {
        try {
            SecurityGridTradingBacktestResultDto result = gridTradingBacktestService.backtest(param);
            return AjaxResult.success("回测成功", result);
        } catch (Exception e) {
            log.error("网格交易回测失败:", e);
            return AjaxResult.error("回测失败: " + e.getMessage());
        }
    }

}
